package com.greenhouse9.prog01.sample;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.cli.*;

public class SampleMain {

	public static void main(String[] args){
		
		Options options = new Options ();
		options.addOption("t", false, "display current time");
		OptionBuilder.withArgName("locale");
		OptionBuilder.hasArg();
		OptionBuilder.withDescription("with Locale");
		
		options.addOption(OptionBuilder.create("c"));
		options.addOption("h", false, "display help");
		
		CommandLineParser parser = new BasicParser();
		
		try {
			CommandLine cl = parser.parse(options, args);

			if(cl.hasOption("h")){
				HelpFormatter formatter = new HelpFormatter();
				formatter.printHelp("Test1", options, true);
				return;
			}
			
			DateFormat df;
			Locale locale;
			
			String contryCode = cl.getOptionValue("c");
			if (contryCode == null){
				locale = Locale.getDefault();
			}
			else {
				locale = new Locale(contryCode);
			}
			
			if(cl.hasOption("t")){
				df = DateFormat.getTimeInstance(DateFormat.FULL, locale);
			}
			else {
				df = DateFormat.getDateInstance(DateFormat.FULL, locale);
			}
			
			System.out.println(df.format(new Date()));
			for(String s: cl.getArgs()){
				System.out.println(s);
			}
		}
		catch (ParseException e){
			e.printStackTrace();
			System.out.println("Usage here.");
		}
		
		
	}
}
